GDataManager      = Packages.it.softphone.commons.gdata.GDataManager;
gdata             = Packages.com.google.gdata.data;
ApplicationConfig   = Packages.it.softphone.spring.ApplicationConfig;


function gdataUploadDocument( sourcePath, sourceDoc, targetFolder, targetName,  username, password, shares ) 
{  

  var manager = GDataManager.createInstance( targetFolder, "http", "docs.google.com");

  manager.login( username, password );

  var sc = ApplicationConfig.getServletContext();
  
  var path = sc.getRealPath( sourcePath );

  var rpt = new java.io.File( path, sourceDoc);

  Log.debug( "REPORT ==> " + rpt.exists() );
  
  manager.service.setConnectTimeout( 15*1000 );
  manager.service.setReadTimeout( 15*1000 );
 
  var ref = manager.uploadDocument(rpt, targetName, null);

  Log.debug( "REF ==> " + ref );

  if( ref!=null && shares!=null && shares.length>0) {

    var url = new java.net.URL(ref.getAclFeedLink().getHref());
    for( var i=0; i<shares.length; ++i ) {
      manager.addShareReader( url, new java.net.URI(shares[i]));
    }
  }
   
  return ref;

}
